<template>
  <div class="lecturer-detail-box">
    <van-nav-bar
      title="讲师详情"
      left-arrow
      :fixed="true"
      :placeholder="true"
      :z-index="999"
      :safe-area-inset-top="true"
      @click-left="goBack"
    />
    <van-list v-model="loading" :finished="finished" finished-text=" " @load="onLoad">
      <div class="lecturer-data">
        <div class="avatar">
          <img :src="lecturerDetail.lectorAvatar" alt="" />
          <div class="sex" :class="{ man: lecturerDetail.sex == 'man', woman: lecturerDetail.sex == 'woman' }">
            <i class="iconfont icon-icon2" v-if="lecturerDetail.sex == 'man'"></i>
            <i class="iconfont icon-icon1" v-else></i>
          </div>
        </div>
        <div class="name">
          {{lecturerDetail.lectorName}}
        </div>
        <div class="people">{{ lecturerDetail.lectorGradeName }}</div>
        <div class="bottom">
          <div>课程：{{ lecturerDetail.courseCount }}</div>
        </div>

        <div class="desc">
          <span class="tit">个人介绍：</span>
          <span class="cont">
            {{ lecturerDetail.synopsis }}
          </span>
        </div>
      </div>
      <div class="lecturer-course">
        <div class="top-filter">
          <div class="status">
            <van-tabs color="#5881db" v-model="activeName" @click="handleClick">
              <van-tab title-class="tab-item" title="课程" name="course"></van-tab>
            </van-tabs>
          </div>
        </div>
        <div class="course-list">
          <div class="course-item" v-for="(item, index) in trainList" :key="index" @click="gotoDetail(item)">
            <div class="course-cont">
              <div class="img">
                <img :src="item.imgUrl" alt="" />

              </div>
              <div class="name">{{ item.title }}</div>
              <div class="people">
                <i class="iconfont icon-tuandui"></i>
                <span>{{ item.requiredNum + item.electiveNum }}人学习</span>
              </div>
            </div>
          </div>
          <div class="nodata" v-if="trainList.length == 0">
            <img src="@static/img/nodata.png" alt="" />
            <div>暂无数据</div>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { getCourseList } from '@/api/course'
import { getLecturerDetails } from '@/api/lecturer'
export default {
  name: 'trainDetail',
  components: {  },
  data() {
    return {
      lectorId: this.$route.query.uuid,
      lecturerDetail: {}, // 讲师详情
      activeName: 'course',
      searchValue: '', // 搜索内容
      trainList: [], // 课程列表 培训列表
      currentPage: 1, // 当前页数
      pageSize: 9, // 一页多少条
      loading: false,
      finished: false
    }
  },
  computed: {},
  mounted() {
    this.getLecturerDetails()
  },
  methods: {
    goBack() {
      this.$router.replace({
        name: 'lecturer',
        query: {}
      })
    },
    onLoad() {

        this.getCourseList()

    },
    // 获取讲师详情
    getLecturerDetails() {
      getLecturerDetails(this.lectorId).then(res => {
        this.lecturerDetail = res.data
      })
    },
    // 切换课程和培训类型
    handleClick(name, title) {

    },

    // 获取课程列表
    getCourseList() {
      this.isLoading = true
      getCourseList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        categoryId: '',
        keyword: this.searchValue,
        lectorId: this.lectorId
      }).then(res => {
        if (res.code == '200') {
          this.trainList = this.trainList.concat(res.rows)
          this.loading = false
          if (res.rows.length < this.pageSize) {
            this.finished = true
          } else {
            if (res.rows.length == res.total) {
              this.finished = true
            } else {
              this.currentPage++
            }
          }
        }
      })
    },
    // 前往学习
    gotoDetail(item) {
      this.$router.push({
          name: 'knowledgeDetail',
          query: {
            uuid: item.uuid,
            learnFrom: 'lecturer',
            lectorId: this.lectorId
          }
        })
    }
  }
}
</script>

<style scoped lang="less">
.lecturer-detail-box {
  width: 100%;
  height: 100%;
  overflow-y: auto;

  .lecturer-course {
    width: 100%;
    box-sizing: border-box;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
  }
  .lecturer-data {
    width: 100%;
    border-bottom: 10px solid #f5f5f5;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
    box-sizing: border-box;
    padding-bottom: 10px;

    .avatar {
      width: 80px;
      height: 80px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        object-fit: cover;
      }
      .sex {
        position: absolute;
        font-size: 20px;
        bottom: 0;
        right: 0;
        width: 20px;
        height: 20px;
        background-color: #fff;
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        &.man {
          background-color: #1677ff;
        }
        &.woman {
          background-color: #f5222d;
        }
      }
    }

    .name {
      white-space: nowrap;
      font-size: 14px;
      color: #333;
      margin-top: 10px;
    }

    .people {
      font-size: 12px;
      color: #5881db;
      margin-top: 10px;
    }

    .bottom {
      width: 100%;
      padding: 0 10px;
      box-sizing: border-box;
      font-size: 12px;
      color: #333;
      height: 20px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-top: 10px;
      div {
        margin: 0 10px;
      }
    }

    .desc {
      width: 100%;
      margin-top: 10px;
      padding: 0 15px;
      box-sizing: border-box;
      text-align: center;

      .tit {
        margin-bottom: 10px;
        font-size: 12px;
        color: #333;
        text-align: center;
      }

      .cont {
        line-height: 22px;
        font-size: 12px;
        color: #333;
        text-align: center;
      }
    }
  }

  .lecturer-course {
    .top-filter {
      width: 100%;
      height: 50px;
      padding: 0 10px;
      box-sizing: border-box;
      background: #fff;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #eee;

      .status {
        display: flex;
        align-items: center;
        box-sizing: border-box;

        /deep/.tab-item {
          padding: 0 10px;
          margin-right: 10px;
          .van-tab__text {
            font-size: 14px !important;
          }
        }
      }
    }

    .course-list {
      width: 100%;
      display: flex;
      align-content: flex-start;
      flex-wrap: wrap;
      padding: 10px 5px 0;
      box-sizing: border-box;

      .nodata {
        width: 100%;
        height: 300px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        img {
          width: 130px;
        }

        div {
          line-height: 50px;
          font-size: 14px;
          color: #999;
        }
      }

      .course-item {
        width: 50%;
        padding: 5px;
        box-sizing: border-box;
        .course-cont {
          width: 100%;
          border: 1px solid #f5f5f5;
          background-color: #fff;
          border-radius: 10px;
          cursor: pointer;
          overflow: hidden;

          .img {
            width: 100%;
            border-radius: 5px;
            overflow: hidden;
            position: relative;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
              transition: all 0.3s;
              -webkit-transition: all 0.3s;
            }

            .type {
              position: absolute;
              top: 10px;
              left: 10px;
              min-width: 50px;
              height: 24px;
              background: rgba(0, 0, 0, 0.3);
              border-radius: 4px;
              display: flex;
              align-items: center;
              justify-content: center;
              padding: 0 6px;
              box-sizing: border-box;

              i {
                width: 4px;
                height: 4px;
                background: #b82121;
                border-radius: 50%;
              }

              i.active {
                background: #3cbb4d;
              }

              span {
                font-size: 12px;
                color: #fff;
                // margin-left: 4px;
              }
            }
          }

          .name {
            width: 100%;
            padding: 0 10px;
            box-sizing: border-box;
            line-height: 25px;
            height: 25px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 12px;
            color: #333;
          }

          .people {
            padding: 0 10px;
            box-sizing: border-box;
            font-size: 12px;
            color: #999;
            height: 25px;
            display: flex;
            align-items: center;

            i.iconfont {
              font-size: 12px;
              margin-right: 5px;
            }
          }
        }
      }
    }
  }
}
</style>
